const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

export const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

export const isEmptyField = (val) => val === '' || val == null

export const subString  = (list, key, length) => {
  return list.map(item => {
    if (item[key].length > length) {
      item[key] = item[key].substring(0, length) + '...'
    }
    return item
  })
}
/*隐藏手机号*/
export const hidePhone = (phone) => {
  return phone.replace(/(\d{3})(\d{4})(.*)/, '$1****$3')
}

/*验证手机号*/
export const checkPhone = (phone) => {
  return /^1\d{10}$/.test(phone)
}
